//package com.tianzmp.ttq.admin.security;
//
//import com.alibaba.fastjson.JSONObject;
//import com.tianzmp.ttq.admin.controller.resdto.UserInfoGetById;
//import com.tianzmp.ttq.admin.service.IUserInfoService;
//import lombok.extern.log4j.Log4j2;
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.core.context.SecurityContextHolder;
//import org.springframework.stereotype.Component;
//import org.springframework.web.filter.OncePerRequestFilter;
//
//import javax.annotation.Resource;
//import javax.servlet.FilterChain;
//import javax.servlet.ServletException;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//import java.util.stream.Collectors;
//
///**
// * @author zhumengping
// */
//@Component
//@Log4j2
//public class JwtVerificationFilter extends OncePerRequestFilter {
//
//    @Resource
//    private IUserInfoService userInfoService;
//
//
//    @Override
//    protected void doFilterInternal(HttpServletRequest req, HttpServletResponse
//            res, FilterChain flter) throws ServletException, IOException {
//        String token = req.getHeader("Authorization");
//        log.info("流程3");
//        if (StringUtils.isBlank(token)){
//            flter.doFilter(req,res);
//            return;
//        }
//        Map<String,String> responseMap = new HashMap<>(16);
//        responseMap.put("code", "500");
//        responseMap.put("data", "");
//        try{
//            //校验token
//            JwtUtils.verify(token);
//        }catch (Exception e){
//            responseMap.put("msg", "token is error");
//            res.setContentType("application/json;charset=utf-8");
//            res.getWriter().println(JSONObject.toJSON(responseMap));
//            return;
//        }
//
//
//        //获取用户权限
//        Long userId = JwtUtils.getToken(token);
//
//        List<GrantedAuthority> userAuthority = this.findUserAuthority(userId);
//
//        UserInfoGetById userInfo = userInfoService.getById(userId);
//
//        SecurityContextHolder.getContext()
//                .setAuthentication(new UsernamePasswordAuthenticationToken(null,null,userAuthority));
//        flter.doFilter(req,res);
//
//    }
//
//    private List<GrantedAuthority> findUserAuthority(Long userId){
//
//
//        List<String> list = userInfoService.getUserId(userId);
//
//        return list.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList());
//
//
//    }
//
//
//}
